﻿<script>

    $(function () {

        $(document).on('click', ".reply_btn", function () {
            var div = $("#" + $(this).data("link-reply"));

            div.fadeIn(200);
            $(this).hide().siblings('.reply_hide').show();
        })
        $(document).on('click', ".reply_hide", function () {
            var div = $("#" + $(this).data("link-reply"));
            div.fadeOut(200);
            $(this).hide().siblings('.reply_btn').show();
        })

        $(document).on("click", "a.toComment", function () {
            var content = $("#content").val();
            var resourceId = $("#ResourceId").val();
            if (content != "" && content != null && resourceId != "" && resourceId != null) {
                $("#commentForm").submit();
            }
            return false;
        });


        $(document).on("click", "a.replyComment", function () {
            var content = $("#" + $(this).data("link-content")).val();
            var toLoginUser = $(this).data("tologinuser");
            var parentComment = $(this).data("parentcomment");
            if (content != "" && content != null && toLoginUser != "" && toLoginUser != null) {
                $("#content").val(content);
                $("#toLoginUser").val(toLoginUser);
                $("#parentComment").val(parentComment);
                $("#commentForm").submit();
            }
        });

        $("#commentMore").click(function () {
            var index = parseInt($(this).attr("data-index"));
            var $this = $(this);
            var resourceId = $("#ResourceId").val();
            if (!isNaN(index) && resourceId != "" && resourceId!=null) {
                var url = "@Url.Action("CommentMore", "comment")";
                $.ajax({
                    url: url,
                    type: "post",
                    data: { resourceId: resourceId ,start:index},
                    success: function (o) {
                        if (o == null || o == "") {
                            $this.html("没有更多了");
                            $this.attr("id", "noMore");
                        }
                        else {
                            $("#commentul").append(o);
                            $this.attr("data-index", (index + 1));
                        }
                    }
                });
            }
        });
    });

</script>
